<?php

ini_set('display_errors', 1);
error_reporting(-1);

require_once '/data/wwwroot/g_vendor/autoload.php';

use Biz\model\brand\Brand;
use Doraemon\model\Fans;
use Doraemon\model\Member;
use Doraemon\model\MyFocus;

const  DEFAULT_PAGESIZE = 200;

//从hhzhome_member.hhz_member查询type=2的uid集合
$designerUidArr = getDesignerUidArr($argv[1]);
addToMyFocus($designerUidArr, Member::AUTH_USER_DESIGNER);


/**
 * @param $page
 * @return array
 */
function getDesignerUidArr($page): array
{
    $field = ['uid'];
    $where = [
        'uid[>]' => 0,
        'type' => Member::AUTH_USER_DESIGNER,
        'LIMIT' => [($page - 1) * DEFAULT_PAGESIZE,DEFAULT_PAGESIZE]
    ];
    return array_column(Member::select($field, $where), 'uid');
}

/**
 * 写入数据到hhz_my_focus
 * @param array $data
 * @param int $followedUid
 * @param int $followedType
 */
function funAdd(array $data, int $followedUid, int $followedType)
{
    foreach ($data as $val) {
        MyFocus::add($val['fans_uid'], $followedUid, $followedType, $val['addtime']);
    }
}

/**
 * @param array $uidArr
 * @param $followedType
 */
function addToMyFocus(array $uidArr, $followedType)
{
    foreach ($uidArr as $uid) {
        $field = ['fans_uid', 'addtime'];
        $where = [
            'uid' => $uid,
        ];
        $data = Fans::select($field, $where);
        echo '用户uid:'.$uid.'粉丝数:'.count($data).PHP_EOL;

        funAdd($data, $uid, $followedType);
    }
}